import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.openqa.selenium.By.id;
import static org.openqa.selenium.By.name;

public class Login {

    public static String userName = "zyusfe";
    public static String password = "zk19881990";

    private final WebDriver driver;

    public Login(WebDriver driver) {
        this.driver = driver;
    }

    public void typeUserName() {
        WebElement loginField = driver.findElement(id("user_login"));
        loginField.sendKeys(userName);
    }

    public void typePassword() {
        WebElement passwordField = driver.findElement(id("user_password"));
        passwordField.sendKeys(password);
    }

    public void clickSignIn(WebDriverWait wait) {
        WebElement signInButton = driver.findElement(name("login"));
        signInButton.click();
        wait.until(ExpectedConditions.titleIs("TRACKS::List tasks"));
    }
}
